package org.jackysoft.cfg.jms.tomcat;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageSender {
	private JmsTemplate jmsTemplate;
	private ActiveMQQueue destination;
	
	
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public void send(final String text) {
		
		jmsTemplate.send(destination,new MessageCreator() {
           
			public Message createMessage(Session session) throws JMSException {
				
				return session.createTextMessage(text);
			}
		});
	}
	
	public void setDestination(ActiveMQQueue destination) {
		this.destination = destination;
	}
}
